package com.example.admin.yuejian21.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.admin.yuejian21.Bean.order;
import com.example.admin.yuejian21.Bean.shaitu;
import com.example.admin.yuejian21.R;
import com.example.admin.yuejian21.ViewHolder.OrderViewHolder;
import com.example.admin.yuejian21.ViewHolder.ShaituViewHoolder;
import com.example.admin.yuejian21.activity.OrderDetailActivity;
import com.example.admin.yuejian21.activity.ShaituDetailActivity;

import java.util.ArrayList;
import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

import static com.example.admin.yuejian21.activity.LoginActivity.username;

/**
 * Created by Admin on 2017/11/2.
 */

public class OrderAdapter extends RecyclerView.Adapter {

    private List<order> OrderList =new ArrayList<>();

    private Context context;
    private LayoutInflater layoutInflater;
    public  static String orderid;
    public static String type;
    public OrderAdapter(Context context, List<order> order){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);

        this.OrderList.addAll(order);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView =
                layoutInflater.inflate(R.layout.item_order,parent,false);

        OrderViewHolder holder =
                new OrderViewHolder(itemView);

        return holder;

    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        OrderViewHolder orderViewHolder =
                (OrderViewHolder) holder;
        final order order= OrderList.get(position);




        String time =order.getUpdate_time();
        String name =order.getName();
        String price=order.getPrice();
        orderid=order.getId();
        String pay=order.getPay();
        String state=order.getVstate();






        orderViewHolder.nameView.setText(name);
        orderViewHolder.orderidView.setText(orderid);
        orderViewHolder.priceView.setText(price);
        orderViewHolder.timeView.setText(time);
        orderViewHolder.totalView.setText(pay);
        orderViewHolder.stView.setText(state);






        if(OrderList.get(position).getThumb()!=null){
            Picasso
                    .with(context)
                    .load("http://172.24.10.175/workout/Uploads/"+OrderList.get(position).getThumb())


                    .into(
                            orderViewHolder.orderView);}
        orderViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, OrderDetailActivity.class);


                orderid = order.getId();
                type=order.getType();


                context.startActivity(intent);

            }
        });


    }

    @Override
    public int getItemCount() {
        return OrderList.size();
    }
}
